class Solution {
public:
    vector<int> distributeCandies(int candies, int num_people)
    {
        vector<int> ans(num_people, 0);
        int num = 1;
        int index = 0;
        while (candies > 0)
        {
            if (candies > num)
            {
                ans[(index++) % num_people] += num;
                candies -= num;
                num++;
            }
            else
            {
                ans[(index++) % num_people] += candies;
                candies = 0;
            }
        }
        return ans;
    }
};